// 表格列配置接口
export interface TableColumn {
  prop: string
  label: string
  width?: string | number
  minWidth?: string | number
  fixed?: boolean | 'left' | 'right'
  align?: 'left' | 'center' | 'right'
  sortable?: boolean | 'custom'
  showOverflowTooltip?: boolean
  render?: any // 自定义渲染组件
  formatter?: (row: any, column: any, cellValue: any, index: number) => string
  hidden?: boolean
}

/**
 * 列设置接口
 */
export interface ColumnSetting {
  /** 列属性名 */
  prop: string
  /** 列标签 */
  label: string
  /** 是否显示 */
  visible: boolean
  /** 排序索引 */
  order: number
}

// 搜索字段接口
export interface SearchField {
  key: string
  label: string
  type: 'text' | 'number' | 'date' | 'datetime' | 'select'
  placeholder: string
  options?: { label: string; value: any }[]
}

// 表格配置接口
export interface TableConfig {
  // 基础配置
  title?: string
  description?: string
  searchFields?: SearchField[]
  
  // 显示控制
  showHeader?: boolean
  showSearch?: boolean
  showPagination?: boolean
  showSelection?: boolean
  showIndex?: boolean
  showActions?: boolean
  
  // 按钮配置
  showAddButton?: boolean
  addButtonText?: string
  showEditButton?: boolean
  showDeleteButton?: boolean
  
  // 自定义头部操作按钮
  customHeaderActions?: {
    text: string
    type?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'default'
    icon?: string
    handler: () => void
  }[]
  
  // 批量操作按钮
  batchActions?: {
    text: string
    type?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'default'
    icon?: string
    handler: string
  }[]
  
  // 表格样式
  stripe?: boolean
  border?: boolean
  height?: string | number
  maxHeight?: string | number
  
  // 操作列配置
  actionWidth?: number
  actionFixed?: boolean | 'left' | 'right'
  
  // 分页配置
  pageSizes?: number[]
  paginationLayout?: string
  
  // 其他表格属性
  tableProps?: Record<string, any>
}

// API配置接口
export interface ApiConfig {
  listApi: (params: any) => Promise<any>
  deleteApi?: (id: string) => Promise<any>
  [key: string]: any
}

// Props接口
export interface CommonTableProps {
  config: TableConfig
  columns: TableColumn[]
  api: ApiConfig
  immediate?: boolean,
}

// Emits接口
export interface CommonTableEmits {
  (e: 'add'): void
  (e: 'edit', row: any, index: number): void
  (e: 'delete', row: any, index: number): void
  (e: 'selection-change', selection: any[]): void
  (e: 'sort-change', sort: any): void
  (e: 'refresh'): void
}